package sandbox;

import org.lwjgl.util.Rectangle;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*;
 

public class CollisionTest {
    int fx = 100, sx = 200;
    int fy = 100, sy = 200;
    int efx = 400, esx = 200;
    int efy = 100, esy = 200;
    Rectangle p = new Rectangle(fx, fy, sx, sy);
    Rectangle e = new Rectangle(efx, efy, esx, esy);
    public CollisionTest() {
        createScreen();
        drawQuad();
    }
     
    public void createScreen() {
        try {
            Display.setDisplayMode(new DisplayMode(600, 400));
            Display.create();
        } catch(LWJGLException e) {
            e.printStackTrace();
            System.exit(0);
        }
         
        while(!Display.isCloseRequested()) {
            drawQuad();
            fx = CollisionKeyboard.checkLeft(fx);
            fx = CollisionKeyboard.checkRight(fx);
            fy = CollisionKeyboard.checkForward(fy);
            fy = CollisionKeyboard.checkBackward(fy);
            if(Collision.quadIntersect(p, e)) {
            	p.setLocation(fx, fy);
            	e.setLocation(sx, sy);
                System.out.println("True!!");
            }
            System.out.println("FX: " + fx);
            System.out.println("FY: " + fy);
            System.out.println("SX: " + sx);
            System.out.println("SY: " + sy);
            System.out.println("EFX: " + efx);
            System.out.println("EFY: " + efy);
            System.out.println("ESX: " + esx);
            System.out.println("ESY: " + esy);
            Display.update();
        }
    }
     
    public void drawQuad() {
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GL11.glOrtho(0, 800, 600, 0, 1, -1);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
         
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glColor3f(0.5f, 0.5f, 1.0f);
        GL11.glBegin(GL11.GL_QUADS);
            GL11.glVertex2f(fx, fy);
            GL11.glVertex2f(fx + sx, fy);
            GL11.glVertex2f(fx + sx, fy + sy);
            GL11.glVertex2f(fx, fy + sy);
        GL11.glEnd();
        GL11.glBegin(GL11.GL_QUADS);
            GL11.glVertex2f(efx, efy);
            GL11.glVertex2f(efx + esx, efy);
            GL11.glVertex2f(efx + esx, efy + esy);
            GL11.glVertex2f(efx, efy + esy);
        GL11.glEnd();
    }
     
    public static void main(String[] args) {
        new CollisionTest();
    }
}